package com.mf.config;

import io.github.heollhai.common.entity.request.SocketMessageRequest;
import jakarta.validation.Valid;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.annotation.Validated;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: lmf
 * @Create: 2024/11/17 14:57
 * Description:  消息中间件配置
 */
@Configuration
@Validated
public class RabbitMqConfig {
    // 交换机名称
    public static final String EXCHANGE_NAME = "basic.exchange-topic";
    // 队列名称
    public static final String QUEUE_NAME = "basic.queue-topic";



    /**
     * 声明交换机
     */
    @Bean("basic.exchange-topic")
    public Exchange declareExchange() {
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    /**
     * 声明队列
     */
    @Bean("basic.queue")
    public Queue declareQueue() {
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    /**
     * 绑定交换机
     */
    @Bean
    public Binding binding(@Qualifier("basic.queue") Queue queue,@Qualifier("basic.exchange-topic") Exchange exchange){
        return BindingBuilder
                .bind(queue)
                .to(exchange)
                .with("basic.#")
                .noargs();
    }

}
